package com.tlgen.orm.common;

import com.tlgen.orm.factory.QueryOperator;
import com.tlgen.orm.utils.SQLGenUtils;

import java.util.List;

import static com.tlgen.orm.utils.ORMUtils.getQueryOperator;

public class Model {

    public static <T> List<T> selectAll(Class<T> tClass) {
        return SQLGenUtils.selectAll(tClass);
    }

    public static <T> List<T> selectAll(Object object) {
        return SQLGenUtils.selectAll(getQueryOperator(object), (Class<T>) object.getClass());
    }

    public static <T> List<T> selectAll(QueryOperator<T> queryOperator, Class<T> tClass) {
        return SQLGenUtils.selectAll(queryOperator, tClass);
    }

    public static <T> T selectById(Object id, Class<T> tClass) {
        return SQLGenUtils.selectById(id, tClass);
    }

    public static <T> T selectOne(QueryOperator<T> queryOperator, Class<T> tClass) {
        return SQLGenUtils.selectOne(queryOperator, tClass);
    }

    public static <T> T selectOne(Object object, QueryOperator<T> queryOperator) {
        return SQLGenUtils.selectOne(getQueryOperator(object), queryOperator, (Class<T>) object.getClass());
    }

    public static <T> T selectOne(Object object) {
        return SQLGenUtils.selectOne(getQueryOperator(object), (Class<T>) object.getClass());
    }

    public static <T> List<T> tree(Class<T> tClass) {
        return SQLGenUtils.tTree(tClass);
    }

    public static <T> void save(Object o) {
        SQLGenUtils.save(o);
    }

    public static <T> void update(Object o) {
        SQLGenUtils.update(o);
    }

    public static <T> void updateSelective(Object o) {
        SQLGenUtils.updateSelective(o);
    }

    public static <T> void update(QueryOperator<T> queryOperator, Object o) {
        SQLGenUtils.update(queryOperator, o);
    }

    public static <T> void updateSelective(QueryOperator<T> queryOperator, Object o) {
        SQLGenUtils.updateSelective(queryOperator, o);
    }

    public static void deleteById(Object id, Class<?> tclass) {
        SQLGenUtils.deleteById(id, tclass);
    }

    public static <T> void deleteLogicalById(Object id, Class<T> tclass) {
        SQLGenUtils.deleteLogicalById(id, tclass);
    }

    public static <T> void delete(QueryOperator<T> queryOperator, Class<T> tclass) {
        SQLGenUtils.delete(queryOperator, tclass);
    }

    public static <T> void delete(Class<T> tclass) {
        SQLGenUtils.delete(tclass);
    }

    public static <T> void saveBatch(List<T> tList) {
        SQLGenUtils.saveBatch(tList);
    }

    public static <T> PageResult<T> selectPage(Integer pageNum, Integer pageSize, QueryOperator<T> queryOperator, Class<T> tClass) {
        return SQLGenUtils.selectPage(pageNum, pageSize, queryOperator, tClass);
    }

}
